home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Easiest way to center a string?
- Date: Wed, 21 Feb 96 15:08:59 GMT
- Organization: none
- Distribution: world
- Message-ID: <824915339snz@genesis.demon.co.uk>
- References: <4fobka$1st@parlor.hiwaay.net> <DMqEG5.8z4@eskimo.com> <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <Pine.A32.3.91.960221001254.156335E-100000@black.weeg.uiowa.edu>
- robinson@blue.weeg.uiowa.edu "The Amorphous Mass" writes:
-
- >On 20 Feb 1996, Tanmoy Bhattacharya wrote:
- >
- >> In article Amorphous Mass <robinson@blue.weeg.uiowa.edu> writes:
- >> <snip>
- >> That's equivalent to strlen(String + -LineLen), which is in turn
- >> equivalent to strlen(String[-LineLen]), and the expression String[-80] is
- >> portable only in the sense that its behavior is undefined on all
- >> platforms. :)
- >>
- >> Sorry there is no trigraph for `&': so if that key is broken, you just
- >> have to get it fixed :-)
- >
- >??? Works fine. My tilde key is broken though, which makes UNIX a real
- >pain.
-
- String + -LineLen is equivalent to &String[-LineLen] except where
- String[-LineLen] tries to access the element one past the end of the
- array.
-
- >> If you meant (strlen(String) - LineLen) / 2 then you will get a
- >> negative length specifier for any string with fewer than LineLen
- >> characters. If you meant (LineLen - strlen(String) / 2, then your
- >>
- >> strlen returns size_t which is guaranteed unsigned. (I am assuming
- >> LineLen is not long.)
- >
- > Right, but strlen(String) would be 12, minus LineLen which is 80, which
- >is -68,
-
- No, it is UINT_MAX (or ULONG_MAX, etc.)-68 (assuming the size_t value doesn't
- get promoted to int or long).
-
- >divided by two is -34, which is the number passed as a width
- >specifier to printf(). I don't think printf("%*s", -34, "hello, world);
- >is worth much. :)
-
- Probably more than (UINT_MAX-68)/2 ! :-) Also with fixed string -------^
-
- > I guess I didn't say that at all clearly the first time. Is it clearer
- >now, or am I _completely_ brain-dead?
-
- You don't provide much in the way of choice there! :-))
-
- Did anybody mention:
-
- (int)((strlen(String) + LineLen) / 2) ?
-
- You just have to decide what to do if the string is longer than the line.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-